package kkk;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that Strafer squares up target and turns gun correctly.
 * 
 * @author Kyle Kakinami
 * 
 */
public class TestStraferAngle extends RobotTestBed {
  /** True if the robot squares up to target enemy. */
  boolean lateral = false;

  /**
   * Specifies that SittingDuck and Strafer are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,kkk.Strafer*";
  }

  /**
   * This test runs for 1 round.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 1;
  }

  /**
   * After each turn, check to see that the robot is lateral to enemy.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    double bodyHeading = robot.getBodyHeading();
    double gunHeading = robot.getGunHeading();

    // Checks to see if gun is 90 left of body
    if (Math.abs((gunHeading + (Math.PI / 2)) - bodyHeading) < 0.001) {
      lateral = true;
    }

  }

  /**
   * After the battle, check to see we've squared up.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check if Strafer is lateral", lateral);
  }
}
